package com.wy.business.market.pda.actions;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.wy.business.market.pda.pojos.UsersRT;
import com.wy.business.market.pda.services.ProductManageService;
import com.wy.framework.actions.AbstractBaseAction;
import com.wy.framework.constants.RtnCodeConstant;
import com.wy.framework.exceptions.ServiceException;
import com.wy.component.communication.IpGetter;

/**
 * 项目名称：openportal
 * 类名称：ProductAction
 * 类描述：商品管理控制层
 * 创建人：张旭星
 * 创建时间：2016-2-14 下午3:32:25
 * 修改人：张旭星
 * 修改时间：2016-2-14 下午3:32:25
 * 版本信息：@version 1.0
 * Copyright (c) 2016万雍科技（上海）有限公司-版权所有  
 * 修改备注：
 * @version 
 */
@ParentPackage("json")
@Namespace("/pda/product")
@ExceptionMappings({ @ExceptionMapping(exception = "java.lange.RuntimeException", result = "error") })
@SuppressWarnings("rawtypes")
public class ProductAction extends AbstractBaseAction {
	private static final long serialVersionUID = 1L;
	private static Log logger = LogFactory.getLog(ProductAction.class);

	@Autowired
	private ProductManageService productManageService;
	
	private List<Map> rows;

	/**
	 * Function Name               get                                   
	 * @return
	 * @throws ServiceException          		             
	 * @description 取得单个商品信息
	 * Modify History:              Date             Programmer       Notes
	 *                            ---------        ---------------  ---------
	 *                      2016-2-14 下午4:54:14           张旭星                     Initial
	 **********************************************************************
	 */
	@Action(value = "productInfo", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
				"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
				"false"}) })
	public String productInfo() throws ServiceException {
		try {
			String barcode=ServletActionContext.getRequest().getParameter("barcode");
//			rows = productManageService.getProductInfo(barcode,loginUser());
		} catch (Exception e) {
			logger.info("系统异常:{}", e);
			rspCode = RtnCodeConstant.RTN_CODE_UNKNOW_ERROR;
		}
		return SUCCESS;
	}
	
	@Action(value = "sellInfo", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
					"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String sellInfo() throws ServiceException {
		try {
			String barcode=ServletActionContext.getRequest().getParameter("barcode");
//			rows = productManageService.getSellInfo(barcode,loginUser());
		} catch (Exception e) {
			logger.info("系统异常:{}", e);
			rspCode = RtnCodeConstant.RTN_CODE_UNKNOW_ERROR;
		}
		return SUCCESS;
	}
	
	@Action(value = "judgeBarcode", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
					"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String judgeBarcode() throws ServiceException {
		try {
			String barcodes=ServletActionContext.getRequest().getParameter("barcodes");
//			rspCode = productManageService.judgeBarcode(barcodes,loginUser());
		} catch (Exception e) {
			logger.info("系统异常:{}", e);
			rspCode = RtnCodeConstant.RTN_CODE_UNKNOW_ERROR;
		}
		return SUCCESS;
	}
	
	@Action(value = "judgeItemNo", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
					"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String judgeItemNo() throws ServiceException {
		try {
			String itemNo=ServletActionContext.getRequest().getParameter("itemNo");
//			rspCode = productManageService.judgeItemNo(itemNo,loginUser());
		} catch (Exception e) {
			logger.info("系统异常:{}", e);
			rspCode = RtnCodeConstant.RTN_CODE_UNKNOW_ERROR;
		}
		return SUCCESS;
	}
	
	@Action(value = "fetchIp", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
					"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String fetchIp() throws ServiceException {
		try {
			rspCode = IpGetter.getIpAddr(ServletActionContext.getRequest());// 获取来自客户端ip网段
		} catch (Exception e) {
			logger.info("系统异常:{}", e);
			rspCode = RtnCodeConstant.RTN_CODE_UNKNOW_ERROR;
		}
		return SUCCESS;
	}
	
	@Action(value = "stockInfo", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
					"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String stockInfo() throws ServiceException {
		try {
			String barcode=ServletActionContext.getRequest().getParameter("barcode");
//			rows = productManageService.getStockInfo(barcode,loginUser());
		} catch (Exception e) {
			logger.info("系统异常:{}", e);
			rspCode = RtnCodeConstant.RTN_CODE_UNKNOW_ERROR;
		}
		return SUCCESS;
	}
	
	@Action(value = "shelfCapacity", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
					"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String shelfCapacity() throws ServiceException {
		try {
			String barcode=ServletActionContext.getRequest().getParameter("barcode");
//			rows = productManageService.getShelfCapacity(barcode,loginUser());
		} catch (Exception e) {
			logger.info("系统异常:{}", e);
			rspCode = RtnCodeConstant.RTN_CODE_UNKNOW_ERROR;
		}
		return SUCCESS;
	}
	
	@Action(value = "labelInfo", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
					"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String labelInfo() throws ServiceException {
		try {
			String barcode=ServletActionContext.getRequest().getParameter("barcode");
//			rows = productManageService.getLabelInfo(barcode,loginUser());
		} catch (Exception e) {
			logger.info("系统异常:{}", e);
			rspCode = RtnCodeConstant.RTN_CODE_UNKNOW_ERROR;
		}
		return SUCCESS;
	}
	
	@Action(value = "changeItemPrice", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
					"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String changeItemPrice() throws ServiceException {
		try {
			String itemNo=ServletActionContext.getRequest().getParameter("itemNo");
			String price=ServletActionContext.getRequest().getParameter("price");
			String changeBeginDate=ServletActionContext.getRequest().getParameter("changeBeginDate");
			String i18n=ServletActionContext.getRequest().getParameter("i18n");
			String reason=ServletActionContext.getRequest().getParameter("reason");
//			UsersRT u = loginUser();
//			rspCode = productManageService.changeItemPrice(itemNo,price,changeBeginDate,u,i18n,reason);
		} catch (Exception e) {
			logger.info("系统异常:{}", e);
			rspCode = RtnCodeConstant.RTN_CODE_UNKNOW_ERROR;
		}
		return SUCCESS;
	}
	
	@Action(value = "calMargin", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
					"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String calMargin() throws ServiceException {
		try {
			String itemNo=ServletActionContext.getRequest().getParameter("itemNo");
			String price=ServletActionContext.getRequest().getParameter("price");
			String i18n = ServletActionContext.getRequest().getParameter("i18n");
//			rspCode = productManageService.calMargin(itemNo,price,loginUser(),i18n);
		} catch (Exception e) {
			logger.info("系统异常:{}", e);
			rspCode = RtnCodeConstant.RTN_CODE_UNKNOW_ERROR;
		}
		return SUCCESS;
	}
	
	@Action(value = "printLabel", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
					"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String printLabel() throws ServiceException {
		try {
			String itemNo=ServletActionContext.getRequest().getParameter("itemNo");
			String groupName=ServletActionContext.getRequest().getParameter("groupName");
			String railcard=ServletActionContext.getRequest().getParameter("railcard");
			String printQty=ServletActionContext.getRequest().getParameter("printQty");
			String i18n = ServletActionContext.getRequest().getParameter("i18n");
//			rspCode = productManageService.printLabel(itemNo,groupName,railcard,printQty,loginUser(),i18n);
		} catch (Exception e) {
			logger.info("系统异常:{}", e);
			rspCode = RtnCodeConstant.RTN_CODE_UNKNOW_ERROR;
		}
		return SUCCESS;
	}
	
	@Action(value = "changePriceInfo", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
					"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String changePriceInfo() throws ServiceException {
		try {
			String barcode=ServletActionContext.getRequest().getParameter("barcode");
//			rows = productManageService.getChangePriceInfo(barcode,loginUser());
		} catch (Exception e) {
			logger.info("系统异常:{}", e);
			rspCode = RtnCodeConstant.RTN_CODE_UNKNOW_ERROR;
		}
		return SUCCESS;
	}
	
	@Action(value = "uploadOutStock", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
					"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String uploadOutStock() throws ServiceException {
		try {
			String barcodes=ServletActionContext.getRequest().getParameter("barcodes");
			String i18n = ServletActionContext.getRequest().getParameter("i18n");
//			rspCode = productManageService.uploadOutStock(barcodes,loginUser(),i18n);
		} catch (Exception e) {
			logger.info("系统异常:{}", e);
			rspCode = RtnCodeConstant.RTN_CODE_UNKNOW_ERROR;
		}
		return SUCCESS;
	}
	
	@Action(value = "uploadOutStockDel", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
					"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String uploadOutStockDel() throws ServiceException {
		try {
			String barcodes=ServletActionContext.getRequest().getParameter("barcodes");
			String i18n = ServletActionContext.getRequest().getParameter("i18n");
//			rspCode = productManageService.uploadOutStockDel(barcodes,loginUser(),i18n);
		} catch (Exception e) {
			logger.info("系统异常:{}", e);
			rspCode = RtnCodeConstant.RTN_CODE_UNKNOW_ERROR;
		}
		return SUCCESS;
	}
	
	@Action(value = "changeShelfCapacity", 
			interceptorRefs = { @InterceptorRef("sessionStack") }, 
			results = { @Result(name = "success", type = "json", params = {
					"noCache", "true", "contentType", "text/html", "ignoreHierarchy",
			"false"}) })
	public String changeShelfCapacity() throws ServiceException {
		try {
			String itemNo=ServletActionContext.getRequest().getParameter("itemNo");
			String linearCapacity=ServletActionContext.getRequest().getParameter("linearCapacity");
			String layer=ServletActionContext.getRequest().getParameter("layer");
			String firstLinearCapacity=ServletActionContext.getRequest().getParameter("firstLinearCapacity");
			String deep=ServletActionContext.getRequest().getParameter("deep");
			String i18n = ServletActionContext.getRequest().getParameter("i18n");
//			rspCode = productManageService.changeShelfCapacity(itemNo,linearCapacity,layer,firstLinearCapacity,deep,loginUser(),i18n);
		} catch (Exception e) {
			logger.info("系统异常:{}", e);
			rspCode = RtnCodeConstant.RTN_CODE_UNKNOW_ERROR;
		}
		return SUCCESS;
	}
	
	public List<Map> getRows() {
		return rows;
	}

	public int getTotal() {
		if (rows == null) {
			return 0;
		} else {
			return rows.size();
		}
	}

}
